package com.biboheart.adapter.support.enums;

import com.biboheart.adapter.support.BaseEnum;
import com.biboheart.adapter.support.EnumValueObject;

import java.util.ArrayList;
import java.util.List;

public enum OperatorEnum implements BaseEnum<String, String> {
    OPERATOR_ADD("+", "加"),
    OPERATOR_SUB("-", "减"),
    OPERATOR_MUL("*", "乘"),
    OPERATOR_DIV("/", "除"),
    OPERATOR_REM("%", "余"),
    OPERATOR_BIT_AND("&", "与"),
    OPERATOR_BIT_OR("|", "或"),
    OPERATOR_BIT_XOR("^", "异或"),
    OPERATOR_BIT_INV("~", "取反"),
    OPERATOR_BIT_LEFT("<<", "左移"),
    OPERATOR_BIT_RIGHT(">>", "右移"),
    ;
    private final String code;
    private final String desc;

    OperatorEnum(String code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    @Override
    public String code() {
        return code;
    }

    @Override
    public String desc() {
        return desc;
    }

    public static OperatorEnum getOperator(String code) {
        OperatorEnum[] operatorEnums = values();
        for (OperatorEnum operatorEnum : operatorEnums) {
            if (operatorEnum.code().equals(code)) {
                return operatorEnum;
            }
        }
        return null;
    }

    public static boolean contains(String code) {
        OperatorEnum[] operatorEnums = values();
        for (OperatorEnum operatorEnum : operatorEnums) {
            if (operatorEnum.code().equals(code)) {
                return true;
            }
        }
        return false;
    }

    public static List<EnumValueObject<String, String>> list() {
        List<EnumValueObject<String, String>> list = new ArrayList<>();
        for (OperatorEnum operatorEnum : values()) {
            list.add(new EnumValueObject<>(operatorEnum.code(), operatorEnum.desc()));
        }
        return list;
    }
}
